package controler.states;
import controler.A_State;
import controler.A_UserCommand;
import controler.userCommands.MoveElement;
import controler.userCommands.SwitchState;
import graphic.RenderObject;
import phx.Vector;
import view.events.LevelEditorViewMouseEvent;

/**
 * @author Damien Mabin
 */

class MoveSelection extends A_State
{

	public function new() 
	{
		super();
		this.addEventListener(LevelEditorViewMouseEvent.EVENT, OnLevelEditorMouseEvent);
	}
	
	private function OnLevelEditorMouseEvent(_Evt:LevelEditorViewMouseEvent):Void
	{
		switch(_Evt.m_Type)
		{
			case MOUSE_DOWN :
			{
				
			}
			case MOUSE_MOVE :
			{
				for (elt in A_State.s_Model.VUE_GetSelection(RenderObject))
				{
					var cmd : A_UserCommand = new MoveElement(null, RenderObject, elt, _Evt.m_MouseMovement.x, _Evt.m_MouseMovement.y, 0);
					cmd.m_Stackable = true;
					A_State.s_Controller.DoUserCommand(cmd);
				}
				for (elt in A_State.s_Model.VUE_GetSelection(Vector))
				{
					var cmd : A_UserCommand = new MoveElement(null, Vector, elt, _Evt.m_MouseMovement.x, _Evt.m_MouseMovement.y, 0);
					cmd.m_Stackable = true;
					A_State.s_Controller.DoUserCommand(cmd);
				}
			}
			case MOUSE_UP :
			{
				if (A_State.s_Model.VUE_GetSelection(RenderObject).length >= 1)
				{
					if (A_State.s_Controller.m_KeyboardKeyState[17/*CTRL*/])
					{
						var cmd : A_UserCommand = new SwitchState(A_State.s_Controller.MULTIPLE_SELECTION);
						A_State.s_Controller.DoUserCommand(cmd);
					}
					else
					{
						var cmd : A_UserCommand = new SwitchState(A_State.s_Controller.SIMPLE_SELECTION);
						A_State.s_Controller.DoUserCommand(cmd);
					}
				}
				else if(A_State.s_Model.VUE_GetSelection(Vector).length >= 1)
				{
					var cmd : A_UserCommand = new SwitchState(A_State.s_Controller.PHX_PT_SIMPLE_SELECTION);
					A_State.s_Controller.DoUserCommand(cmd);
				}
			}
			case MOUSE_WHEEL : 
			{
				
			}
		}
	}
}